package com.paulshiyc.imserver.controller;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.socket.WebSocketSession;

import com.paulshiyc.imserver.bean.User;

/**
 * 提供一些公用方法及全局controller配置等
 * @author PaulShi
 *
 */
public class BaseController {
	protected Logger logger = LogManager.getLogger(BaseController.class);
	/** 初始化所有用户 此后续应为数据库维护*/
	public static HashMap<String,User> users = new HashMap<String,User>();
	/** 
	 * 存放用户登录状态key:sessionId value : user
	 * 用于验证session合法 维持登录状态
	 * 	后续可用redis 或其他方式替换
	 */
	public static ConcurrentHashMap<String, User> sessionAndUser = new ConcurrentHashMap<String, User>();
	
	/** 存放username与session关联*/
	public static ConcurrentHashMap<String,String> userNameAndSession = new ConcurrentHashMap<String,String>();
	/**存放im在线用户*/
	public static ConcurrentHashMap<String,WebSocketSession> onlinUser = new ConcurrentHashMap<String, WebSocketSession>();
//	初始化维护用户
	public BaseController() {
		BaseController.users.put("paul", new User(1, "paul", "paul", "率德布耀布耀德","1.jpg"));
		BaseController.users.put("xuanxuan", new User(1, "xuanxuan", "xuanxuan", "城北徐公","2.jpg"));
	}
}
